#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e6+5;
long long d[N],v[N],a[N],p[N],u[M],w[N],q[N];
bool o[M];
double s[N];
long long read()
{
	long long x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')f=-f;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
void sv()
{
	int n=read(),m=read(),l=read(),x=read(),cnt=0;
	for(int i=0;i<n;i++)
	{
		d[i]=read(),v[i]=read(),a[i]=read();
		if(a[i]!=0)
		{
			s[i]=(1.0*x*x-v[i]*v[i])/(2.0*a[i]);
			if(s[i]<0)
			{
				if(a[i]>0)s[i]=0;
				else s[i]=-1;
			}
			else if(d[i]+s[i]>l)
			{
				if(a[i]>0)s[i]=-1;
				else s[i]=-2;
			}
		}
		else
		{
			if(v[i]>x)s[i]=-2;
			else s[i]=-1;
		}
		if(s[i]!=-1&&s[i]!=-2)s[i]+=d[i];
	}
	for(int i=0;i<m;i++)p[i]=read(),o[p[i]]=true;
	if(o[0])u[0]=1;
	for(int i=1;i<=l;i++)u[i]=u[i-1]+o[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]>0&&s[i]!=-1&&s[i]!=-2)w[i]=u[l]-u[(int)s[i]-1];
		else if(a[i]<0&&s[i]!=-1&&s[i]!=-2)w[i]=u[(int)s[i]]-u[d[i]-1];
		else if(s[i]==-2)w[i]=u[l]-u[d[i]-1];
		if(w[i]>0)q[cnt++]=i;
	}
	printf("%d %d",cnt,rand());
	return;
}
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	srand(time(0));
	int t=read();
	for(int i=0;i<t;i++)sv(),puts("");
	return 0;
}